<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>配置项toolbox-工具栏</title>
  <script src="./echarts.js"></script>
  <style lang="css">
    #chart1 {
      width: 1000px;
      height: 800px;
      /* border: 1px solid red; */
      float: left;
    }
  </style>
</head>
<body>
  <div id="chart1"></div>

  <script>
    const myChart1 = echarts.init(document.getElementById('chart1'));

    myChart1.setOption({
      title: {
        text: '未来一周气温变化',
        subtext: '纯属虚构',
      },
      legend: {},
      tooltip: {
        trigger: 'axis',
      },
      toolbox: {
        show: true,
        showTitle: true,
        itemGap: 10,
        right: '10%',
        feature: { // 想让哪个工具展示就写那个工具的配置
          saveAsImage: { // 保存为图片
            show: true,
            type: 'png',
            name: '图片名称',
            backgroundColor: 'pink',
            excludeComponents: ['toolbox', 'title', 'legend'], // 下载的图片不包括哪些部分
            title: '保存图片lala',
            pixelRatio: 2,
            iconStyle: {
              color: 'blue',
            },
            emphasis: { // emphasis: 高亮
              iconStyle: {
                color: 'red',
              }
            },
          },
          restore: { // 配置项还原
            show: true,
            title: '还原',
            iconStyle: {
              color: 'blue',
            },
            emphasis: { // emphasis: 高亮
              iconStyle: {
                color: 'red',
              }
            },
          },
          dataView: { // 数据视图
            show: true,
            title: '我是数据试图',
            readOnly: false,
            optionToContent: function(opt) {
              var axisData = opt.xAxis[0].data;
              var series = opt.series;
              var table = '<table style="width:100%;text-align:center"><tbody><tr>'
                          + '<td>时间</td>'
                          + '<td>' + series[0].name + '</td>'
                          + '<td>' + series[1].name + '</td>'
                          + '</tr>';
              for (var i = 0, l = axisData.length; i < l; i++) {
                  table += '<tr>'
                          + '<td>' + axisData[i] + '</td>'
                          + '<td>' + series[0].data[i] + '</td>'
                          + '<td>' + series[1].data[i] + '</td>'
                          + '</tr>';
              }
              table += '</tbody></table>';
              return table;
            },
            contentToOption (container, opt) {
              console.log(container, opt)
            },
            lang: ['数据视图', '关闭', '刷新'],
          },
          dataZoom: { // 区域缩放
            xAxisIndex: 0,
            yAxisIndex: 0,
            title: {
              zoom: '缩放',
              back: '还原'
            },
          },
          magicType: {
            type: ['line', 'bar', 'stack', 'tiled'], // 必须设置才生效
          },
        },
      },
      xAxis: {
        data: ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日'],
        boundaryGap: false, // 开始结束点是否留白
      },
      yAxis: {
        axisLabel: {
          formatter: '{value}℃',
        },
      },
      grid: {},
      series: [
        {
          name: '最高气温',
          type: 'line',
          data: [11, 11, 15, 13, 12, 13, 10],
        },
        {
          name: '最低气温',
          type: 'line',
          data: [1, -2, 2, 5, 3, 2, 0],
        },
     ],
    })
  </script>
</body>
</html>